// pages/realnamedtl/realnamedtl.js

const app = getApp()
const pathUrl = app.globalData.pathUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    proAry: ['实名认证', '发起公证', '活体检测', '签署完成'],
    agree: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var telphone = wx.getStorageSync('telphone');
    var userId = wx.getStorageSync('userId')
    var writNumber = wx.getStorageSync('writNumber')
    var caseNumber = wx.getStorageSync('caseNumber')
    that.setData({
      telphone: telphone,
      writNumber: writNumber,
      caseNumber: caseNumber,
      userId: userId,
    })
    this.getGuset();
    // this.getResult();
  },
  ocrNameInput: function (e) {
    this.setData({
      ocrName: e.detail.value
    })
  },
  //ocr身份证号
  idCardInput: function (e) {
    this.setData({
      idCard: e.detail.value
    })
  },
  agree: function (e) {
    console.log(e.detail.value)
    if (e.detail.value == '') {
      this.setData({
        agree: false
      });
    } else {
      this.setData({
        agree: true
      });
    }
  },
  getResult: function () {
    var that = this;
    var userId = that.data.userId;
    var caseNumber = that.data.caseNumber;
    var writNumber = that.data.writNumber;
    var data = {
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
    }
    console.log(data)
    wx.request({
      url: pathUrl + '/fxy/1/checkSignIdentityVerify',
      method: 'POST',
      data: data,
      success: function (res) {
        console.log(res)
        var data = JSON.parse(res.data.message).resultData
        // console.log(JSON.parse(res.data.message).resultData.authDesc)
        that.setData({
          result: data.authDesc
        })
        wx.showModal({
          title: '提示',
          content: data.authDesc,
          showCancel: false,
            success(res){
              if (data.authCode == '1000'){
                wx.navigateTo({
                  url: '/pages/code/code',
                })
              }else{
                // wx.switchTab({
                //   url: '/pages/index/index',
                // })
                wx.navigateTo({
                  url: '/pages/index/index',
                })
              }
            }
        })
      
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function (res) { }
    });
  },
  getGuset: function () {
    var that = this;
    var telphone = that.data.telphone;
    wx.request({
      url: pathUrl + '/gzgl/fxyGzgl02/list',
      method: 'GET',
      data: {
        query12: telphone,
      },
      success: function (res) {
        console.log(res.data.result.records);
        var list = res.data.result.records;
        that.setData({
          list: list,
          orcName: list[0].query13,
          idCard: list[0].query15
        })
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function (res) { }
    });
  },
  // 再试一次 
  goTry: function () {
    wx.navigateBack({
      delta: 1,
    });
  },
  // 提交信息
  goSub: function () {
    var that = this;
    var fileId = wx.getStorageSync('fileId')
    var fileId1 = wx.getStorageSync('fileId1')
    var userId = wx.getStorageSync('userId')
    var idCard = that.data.idCard;
    var orcName = that.data.orcName;
    var data = {
      userId: userId,
      name: orcName,
      idCode: idCard,
      humanFaceFileId: fileId,
      nationalEmblemFileId: fileId1,
    }
    console.log(data)
    wx.request({
      url: pathUrl + '/fxy/1/doRealnameByOCR2Element',
      method: 'POST',
      data: data,
      success: function (res) {
        console.log(res)
        wx.navigateTo({
          url: '../notificationbook/notificationbook',
        })
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function (res) { }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})